<template>
	<view>
		<!-- <view class="tankswiper">
			<zetank-swiper :height="140" :radius="12" :imageList="imageList" type="default"></zetank-swiper>
		</view> -->
		<view class="" style="position: sticky;top: 0;z-index: 1;background: #FFFFFF;">
			<view class="" :style="'height: '+statusBarHeight+'px;'"></view>
			<view class="shopsearch ">
				<view class="inputs flex-between">
					<view class="flex" style="align-items: center;">
						<image src="../../static/search.png" mode=""></image>
						<input type="text" v-model="keyword" placeholder="搜一搜" placeholder-class="inputclo" />
					</view>
					<view class="serbtn" @click="btninput">搜索</view>
				</view>
				<!-- <image src="../../static/shopcar.png" mode="" @click="$fun.jump('/pageC/shop/shopcar')"></image> -->
			</view>
			<u-tabs style="margin-left: 10rpx;" :inactiveStyle="{color: '#999999' }" :list="tabList" lineColor='#5990FF'
				:current="tabIndex" lineHeight='4' lineWidth='18' @click="changeTab"></u-tabs>
		</view>
		<view class="" v-if="tabIndex==0">
			<view class="sline"></view>
			<view class="navlist">
				<view class="navitem" v-for="(item,index) in classList" :key="index" @click="jump(item.url)">
					<image :src="$fun.imgUrl(item.image)" mode=""></image>
					<view class="">{{item.name}}</view>
				</view>
			</view>
		</view>
		<scroll-view scroll-y="true">
			<view class="shoplist">
				<view class="shoplist_goods" v-for="(item,index) in product" :key="index"
					@click="$fun.jump(`/pageC/shop/shopdetail?id=${item.id}&from=${item.from}`)">
					<image :src="$fun.imgUrl(item.image)" mode=""></image>
					<view class="text">{{item.name}}</view>
					<view class="num"> <text style="font-size: 22rpx;">￥</text>{{item.money}} </view>
				</view>
			</view>
		</scroll-view>
		<view style="height: 150rpx;">

		</view>
		<TabBar :tabBarShow="1"></TabBar>
	</view>
</template>

<script>
	import zetankSwiper from "@/components/zetank-swiper/components/zetank-swiper/zetank-swiper.vue"
	export default {
		components: {
			zetankSwiper
		},
		data() {
			return {
				scrollheight: 0,
				statusBarHeight: 0,
				imageList: [],
				tabList: [],
				product: [],
				keyword: '',
				tabIndex: 0,
				from: '',
				classList: []
			}
		},
		onLoad() {
			const phoneInfo = uni.getSystemInfoSync(); // 获取手机系统信息
			this.statusBarHeight = phoneInfo.statusBarHeight
			this.scrollheight = uni.getWindowInfo().windowHeight - 322 - this.statusBarHeight
			this.$fun.ajax.post('index/index', {}).then(res => {
				// console.log(res)
				let imgList = res.data.advert
				for (var i = 0; i < imgList.length; i++) {
					imgList[i].src = this.$fun.imgUrl(imgList[i].image)
				}
				this.imageList = imgList
				this.classList = res.data.shop_cat
			})
			this.$fun.ajax.post('index/goodstype', {}).then(res => {
				// console.log(res)
				this.tabList = res.data
				this.getShopList(res.data[0].id)
			})
		},
		onShow() {

		},
		methods: {
			btninput() {
				uni.$u.throttle(this.btnAClick, 500)
			},
			btnAClick() {
				console.log('serch')
				this.tabIndex = 0
				this.getShopList(this.tabList[this.tabIndex].id)
			},
			changeTab(res) {
				this.tabIndex = res.index
				this.keyword = ''
				this.getShopList(this.tabList[res.index].id)
			},
			jump(url) {
				this.$fun.jump(url)
			},
			getShopList(id) {
				this.$fun.ajax.post('index/type_goods', {
					type: id,
					keyword: this.keyword
				}).then(res => {
					// console.log(res)
					for (var i = 0; i < res.data.length; i++) {
						if (res.data[i].label) {
							res.data[i].label = res.data[i].label.split(',')
						} else {
							res.data[i].label = []
						}
					}
					res.data.map((item) => {
						if (item.category_id == 85) {
							item.from = 1
						} else if (item.category_id == 86) {
							item.from = 2
						} else {
							item.from = 0
						}


					})
					this.product = res.data
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #EEF0F5;
	}

	.shopsearch {
		height: 88rpx;
		margin: 0 30rpx;
		display: flex;
		align-items: center;

		image {
			width: 56rpx;
			height: 56rpx;
			margin-left: 30rpx;
		}


		.inputs {
			/* #ifndef MP-WEIXIN */
			width: 690rpx;
			/* #endif */
			/* #ifdef MP-WEIXIN */
			width: 400rpx;

			/* #endif */
			height: 72rpx;
			background: #F6F6F6;
			border-radius: 32rpx;
			display: flex;
			align-items: center;

			input {
				/* #ifndef MP-WEIXIN */
				width: 420rpx;
				/* #endif */
				/* #ifdef MP-WEIXIN */
				width: 380rpx;

				/* #endif */
			}

			.serbtn {
				width: 120rpx;
				height: 56rpx;
				background: #5990FF;
				border-radius: 28rpx;
				font-weight: 500;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 56rpx;
				text-align: center;
				margin-right: 8rpx;
			}

			.inputclo {
				font-weight: 400;
				font-size: 28rpx;
				color: #CCCCCC;
			}

			image {
				width: 32rpx;
				height: 32rpx;
				margin-left: 20rpx;
				margin-right: 10rpx;
			}
		}
	}

	.sline {
		width: 750rpx;
		height: 16rpx;
		background: #EEF0F5;
	}

	.navlist {
		// height: 162rpx;
		width: 750rpx;
		background: #FFFFFF;
		display: grid;
		grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
		padding: 0rpx 0 30rpx;

		.navitem {
			font-weight: 500;
			font-size: 20rpx;
			color: #333333;
			width: 150rpx;
			text-align: center;
			margin-top: 30rpx;

			image {
				width: 72rpx;
				height: 72rpx;
			}
		}
	}

	.tankswiper {
		width: 690rpx;
		height: 280rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: 20rpx auto 0;
	}

	.shoplist {
		width: 750rpx;
		// background: #F5F1EE;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		flex-direction: row;
		padding: 30rpx 30rpx 30rpx;
		box-sizing: border-box;

		&_goods {
			width: 336rpx;
			height: 426rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			padding: 20rpx;
			margin-bottom: 30rpx;

			image {
				width: 296rpx;
				height: 296rpx;
				border-radius: 16rpx;
			}

			.text {
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				margin: 10rpx 0 0rpx;
			}

			.num {
				font-weight: 600;
				font-size: 32rpx;
				color: #ED4961;
			}
		}
	}
</style>